package com.css.fxfzypg.modules.similitudeAnalyse.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.hypergraph.service.HypergraphService;
import com.css.fxfzypg.modules.similitudeAnalyse.service.SimAnalyseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description: fxfzypg
 * @Author: lhl
 * @CreateDate: 2023/4/19 10:00
 * 定时获取中国地震台网系统的真实地震信息，并生成地震影响场，
 * 最终获取相似性分析结果
 */
@Slf4j
@RestController
@RequestMapping("/schSettingSeismic")
public class SchSettingSeismicController {
    @Resource
    private SimAnalyseService simAnalyseService;
    @Resource
    HypergraphService hypergraphService;

    /**
     * 分析结果保存
     * @return
     * @throws Exception
     * 正式环境将定时放开
     */
   // @Scheduled(cron = "0 */1 * * * ?")
    @PostMapping("/analyseResultSave")
    public RestResponse similitudeAnalyse() {
        RestResponse response = null;
        try {
            response = simAnalyseService.similitudeAnalyse1();
            //刷新指定超图工作空间数据源数据集
            boolean bool1 = hypergraphService.getWorkspaceReload("real_seismic_influenceflied");
            //刷新指定超图工作空间数据源数据集
            boolean bool2 = hypergraphService.getWorkspaceReload("real_earthquake_info");

            if (response.getCode()==200) {
                log.info("分析并保存成功！");
                response.setMessage("分析并保存成功！");
            }else {
                log.error(response.getMessage());
            }
        }catch (Exception e){
            e.printStackTrace();
            response =  RestResponse.fail("分析并保存失败！");
        }
        return response;
    }

    /**
     * 分析结果保存
     * @return
     * @throws Exception
     * 测试数据
     */
    /*@PostMapping("/analyseResultSaveTest")
    public RestResponse similitudeAnalyseTest() {
        RestResponse response = null;
        try {
            response = simAnalyseService.similitudeAnalyse1Test();
            if (response.getCode()==200) {
                log.info("分析并保存成功！");
                response.setMessage("分析并保存成功！");
            }else {
                log.error(response.getMessage());
            }
        }catch (Exception e){
            e.printStackTrace();
            response =  RestResponse.fail("分析并保存失败！");
        }
        return response;
    }*/
}
